import { createRouter, createWebHistory } from 'vue-router'

import routes from './route'

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  // 如果访问的不是登录页，且用户未登录，则重定向到登录页
  if (to.path !== '/login' && !localStorage.getItem('user')) {
    next('/login')
  } else {
    next()
  }
})

export default router 